/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.ssau.berlin.jsf.converters;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import ru.ssau.berlin.ejb.facade.*;
import ru.ssau.berlin.entity.GroupAttribute;
import ru.ssau.berlin.entity.PersonAttribute;
import ru.ssau.berlin.framework.JNDIHelper;

/**
 *
 * @author Caesar
 */
public class GroupAttributeConverter implements Converter {

    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        try {
            return ((GroupFacadeLocal) InitialContext.doLookup(
                JNDIHelper.getBeanName(GroupFacade.class)))
                .findGroupAttribute(Long.parseLong(value));
        } catch (NamingException ex) {
            Logger.getLogger(GroupAttributeConverter.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public String getAsString(FacesContext context, UIComponent component, Object value) {
        return ((GroupAttribute)value).getId().toString();
    }

}
